package com.film.rowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.film.domain.Film;
import com.film.domain.FilmOffice;
import com.film.domain.FilmOrder;
import com.film.domain.FilmSeat;
import com.film.domain.FilmShowings;
import com.film.domain.User;

public class OrderRowMapper implements RowMapper<FilmOrder>{

	@Override
	public FilmOrder mapRow(ResultSet res, int arg1) throws SQLException {
		FilmOrder order = new FilmOrder();
		order.setOrderId(res.getInt("order_id"));
		order.setOrderNum(res.getString("order_num"));
		
		User user = new User();
		user.setuId(res.getInt("u_id"));
		user.setuNickName(res.getString("u_nickName"));
		order.setUser(user);
		
		FilmSeat filmSeat = new FilmSeat();
		filmSeat.setSeatId(res.getInt("seat_id"));
		filmSeat.setSeatNumber(res.getString("seat_number"));
		order.setFilmSeat(filmSeat);
		
		order.setOrderFlag(res.getInt("order_flag"));
		
		FilmShowings filmShowings = new FilmShowings();
		filmShowings.setShowingsId(res.getInt("showings_id"));
		
		Film film = new Film();
		film.setFilmId(res.getInt("film_id"));
		film.setFilmName(res.getString("film_name"));
		film.setFilmForeignName(res.getString("film_foreignName"));
		film.setFilmPlace(res.getString("film_place"));
		film.setFilmTime(res.getString("film_time"));
		film.setFilmShowTime(res.getString("film_showTime"));
		film.setFilmImg(res.getString("film_img"));
		film.setIsDelete(res.getInt("is_delete"));
		film.setBoxoffice(res.getFloat("boxoffice"));
		film.setExpect(res.getInt("expect"));
		film.setFilmIunguage(res.getString("film_lunguage"));
		film.setFilmIntroduce(res.getString("film_introduce"));
		filmShowings.setFilm(film);
		
		filmShowings.setShowingsDay(res.getString("showings_day"));
		filmShowings.setShowingsStartTime(res.getString("showings_starttime"));
		filmShowings.setShowingsEndTime(res.getString("showings_endtime"));
		
		FilmOffice filmOffice = new FilmOffice();
		filmOffice.setOffId(res.getInt("off_id"));
		filmOffice.setOffName(res.getString("off_name"));
		filmShowings.setFilmOffice(filmOffice);
		
		filmShowings.setShowingsPrice(res.getDouble("showings_price"));
		filmShowings.setShowingsCreateTime(res.getString("showings_createTime"));
		filmShowings.setShowingsUpdateTime(res.getString("showings_updateTime"));
		filmShowings.setIsDelete(res.getInt("is_delete"));
		
		order.setFilmShowings(filmShowings);
		
		order.setCreateTime(res.getString("create_time"));
		return order;
	}

}
